import java.util.*;

public class Demo23 {
    static int N = 100010;
    static ArrayList<int[]> list = new ArrayList<>();
    static int[] a;

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();

        for(int i = 0; i < n; i++){
            a = new int[2];
            a[0] = scan.nextInt();
            a[1] = scan.nextInt();
            list.add(a);
        }
        list.sort(new Comparator<int[]>(){
            @Override
            public int compare(int[] o1, int[] o2){
                return o1[0] - o2[0];
            }
        });
        int k = 0;
        int r = Integer.MIN_VALUE;
        for(int a[]: list){
            if(a[0] > r){
                k++;
            }
            r = Math.max(r,a[1]);
        }
        System.out.print(k);

    }
}
